<?php

/**
 * UserIdentity represents the data needed to identity a user.
 * It contains the authentication method that checks if the provided
 * data can identity the user.
 */

class UserIdentity extends CUserIdentity
{

	private $_id;
	
    public function authenticate()
    {
        $usuario=Usuario::model()->find('login = :login',array(':login'=>$this->username));

        if($usuario === null)
        {
            $this->errorCode=self::ERROR_USERNAME_INVALID;
        }else if($usuario->senha!==md5($this->password . Yii::app()->params["saltString"]))
        {
            $this->errorCode=self::ERROR_PASSWORD_INVALID;
        }else
        {
            $this->_id=$usuario->id_usuario;
            $this->setState('title', $usuario->login);
            $this->setState('acesso', $usuario->admin);
            $this->errorCode=self::ERROR_NONE;
        }
        return !$this->errorCode;
    }
    
    public function getId()
    {
        return $this->_id;
    }
}